package com.leezt.designpattern.creation.s02Factory.basic;

import com.leezt.designpattern.creation.s02Factory.basic.service.*;

import java.util.HashMap;
import java.util.Map;

public class RuleConfigParserFactoryMap {
    //工厂的工厂
    private static final Map<String, IRuleConfigParserFactory> cachedFactories = new HashMap<>();
    static {
        cachedFactories.put("json", new JsonRuleConfigParserFactory());
        cachedFactories.put("xml", new XmlRuleConfigParserFactory());
        cachedFactories.put("yaml", new YamlRuleConfigParserFactory());
        cachedFactories.put("properties", new PropertiesRuleConfigParserFactory());
    }
    public static IRuleConfigParserFactory getParserFactory(String type) {
        if (type == null || type.isEmpty()) {      return null;    }
        return cachedFactories.get(type.toLowerCase());
    }
}
